package me.ezitku.base.ShapeViews

import android.graphics.Color
import android.util.AttributeSet
import android.view.View
import android.widget.TextView
import me.ezitku.base.R

/**
 * Created by yurqi on 2018/3/7.
 * QQ: 906120575 | Wechat : kalip008
 * Tashkin Company
 */
interface IShapeView : IShapeViewAttribute {



    fun View.setShape(attrs: AttributeSet) {

        val attr = context.obtainStyledAttributes(attrs, R.styleable.ShapeView)
        //      Normal
        _radius = attr.getDimension(R.styleable.ShapeView_radius, 0f)
        val _stroke_width = attr.getInt(R.styleable.ShapeView_stroke_width, 0)
        val _stroke_color = attr.getColor(R.styleable.ShapeView_stroke_color, 0)
        val _solid_color = attr.getColor(R.styleable.ShapeView_solid_color, 0)
        val _text_color = attr.getColor(R.styleable.ShapeView_text_color, Color.parseColor("#000000"))

//        Press
        val _press_radius = attr.getDimension(R.styleable.ShapeView_press_radius, _radius)
        val _press_stroke_width = attr.getInt(R.styleable.ShapeView_press_stroke_width, _stroke_width)
        val _press_stroke_color = attr.getColor(R.styleable.ShapeView_press_stroke_color, _stroke_color)
        val _press_solid_color = attr.getColor(R.styleable.ShapeView_press_solid_color, _solid_color)
        val _press_text_color = attr.getColor(R.styleable.ShapeView_press_text_color, _text_color)


        //        Focus
        var _focus_radius = attr.getDimension(R.styleable.ShapeView_focus_radius, _radius)
        var _focus_stroke_width = attr.getInt(R.styleable.ShapeView_focus_stroke_width, _stroke_width)
        var _focus_stroke_color = attr.getColor(R.styleable.ShapeView_focus_stroke_color, _stroke_color)
        var _focus_solid_color = attr.getColor(R.styleable.ShapeView_focus_solid_color, _solid_color)
        var _focus_text_color = attr.getColor(R.styleable.ShapeView_focus_text_color, _text_color)


        Background {

            //            focus {
//                radius = _focus_radius
//                strokeWidth = _focus_stroke_width
//                strokeColor = _focus_stroke_color
//                color = _focus_solid_color
//                textColor = _focus_text_color
//            }

            press {
                radius = _press_radius
                strokeWidth = _press_stroke_width
                strokeColor = _press_stroke_color
                color = _press_solid_color
                textColor = _press_text_color
            }

            normal {
                radius = _radius
                strokeWidth = _stroke_width
                strokeColor = _stroke_color
                color = _solid_color
                textColor = _text_color
            }
        }
    }

    fun TextView.init() {
        Background {
            press {
                radius = _press_radius

                strokeWidth = _press_stroke_width
                strokeColor = _press_stroke_color

                dashWidth = _press_dash_width
                dashGap = _press_dash_gap

                color = _press_solid_color

                textColor = _press_text_color
            }

            normal {
                radius = _radius

                strokeWidth = _stroke_width
                strokeColor = _stroke_color

                dashWidth = _dash_width
                dashGap = _dash_gap

                color = _solid_color

                textColor = _text_color
            }
        }
    }
}